
package com.soft.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.soft.entity.Changjia;
import com.soft.entity.Good;
import com.soft.mapper.ChangjiaMapper;
import com.soft.mapper.GoodMapper;
@Service
public class ChangjiaService {
	

	    @Autowired
	    private GoodMapper goodMapper;

	    @Autowired
	    private ChangjiaMapper changjiaMapper;

	    // 根据部门名称，查询该部门的所有员工
	    public List<Changjia> queryByGoodName(String name) {
	        QueryWrapper<Good> goodWrapper = new QueryWrapper<>();
	        goodWrapper.eq("good_name", name);
	        Good good = goodMapper.selectOne(goodWrapper);
	        
	        QueryWrapper<Changjia> changjiaWrapper = new QueryWrapper<>();
	        changjiaWrapper.eq("good_id", good.getGoodId());
	        
	        List<Changjia>changjiaList = changjiaMapper.selectList(changjiaWrapper);
	        return changjiaList;
	    }
	    
	    public int  updateChangjia(String goodname,String changjianame,String  changjianumber  ) {
	        // 先根据新的部门名称查询部门信息，获取部门ID
	        QueryWrapper<Good> goodWrapper = new QueryWrapper<>();
	        goodWrapper.eq("good_name", goodname);
	        Good good = goodMapper.selectOne(goodWrapper);

	        // 创建条件构造器，用于根据姓名查询要修改的用户
	        UpdateWrapper<Changjia> changjiaUpdateWrapper = new UpdateWrapper<>();
	        changjiaUpdateWrapper.eq("good_id",good.getGoodId());
	        changjiaUpdateWrapper.eq("changjia_name", changjianame);
	        Changjia changjia=new Changjia();
	        changjia.setChangjiaNumber(changjianumber);
	        QueryWrapper<Changjia> changjiaWrapper = new QueryWrapper<>();
	        int num=changjiaMapper.update(changjia,changjiaUpdateWrapper);
	        return num;
	        
	    }
}

